/*---------------------------------------------------
-----------------------------------------------------
Filename:	eq.m
Version:	2.0

Type:		maki
Date:		25. Jun. 2007 - 11:30 
Author:		Martin Poehlmann aka Deimos
E-Mail:		martin@skinconsortium.com
Internet:	www.skinconsortium.com
		www.martin.deimos.de.vu
-----------------------------------------------------
---------------------------------------------------*/

#include <lib/std.mi>

#define CENTER_VAR eqGroup
#include <lib/centerlayer.m>

Global Group frameGroup;
Global Slider slidercb;
Global Text fadertext;
Global Button CFIncrease, CFDecrease, eqon, eqauto;
Global ToggleButton Crossfade;
Global GuiObject CrossfadeActive, eqonActive, eqautoActive;
Global Int CrossfadeActive_Y, eqonActive_Y, eqautoActive_Y;
Global Button btnEQp12,btnEQ0,btnEQm12;

System.onScriptLoaded()
{
	frameGroup = getScriptGroup();
	_eqGroupInit(frameGroup.findObject("info.component.eq.content"), frameGroup, 1, 0);
	slidercb = frameGroup.findObject("sCrossfade");
	fadertext = frameGroup.findObject("CFDisplay");
	CFIncrease = frameGroup.findObject("CrossfadeIncrease");
	CFDecrease = frameGroup.findObject("CrossfadeDecrease");
	Crossfade = frameGroup.findObject("Crossfade");
	CrossfadeActive = frameGroup.findObject("CrossfadeActive");
	CrossfadeActive_Y = CrossfadeActive.getGuiY();

	eqon = frameGroup.findObject("eqonoff");
	eqonActive = frameGroup.findObject("eqonoffActive");
	eqonActive_Y = eqonActive.getGuiY();

	eqauto = frameGroup.findObject("eqauto");
	eqautoActive = frameGroup.findObject("eqautoActive");
	eqautoActive_Y = eqautoActive.getGuiY();

	btnEQp12 = frameGroup.findObject("EQ_p12");
	btnEQ0 = frameGroup.findObject("EQ_0");
	btnEQm12 = frameGroup.findObject("EQ_m12");

	slidercb.onSetPosition(slidercb.getPosition());

	Crossfade.onToggle(Crossfade.getActivated());
}

slidercb.onSetPosition(int val)
{
	String s = IntegerToString(val);
	fadertext.setText(s);
}

CFIncrease.onLeftClick()
{
	slidercb.SetPosition(slidercb.getPosition()+1);
}

CFDecrease.onLeftClick()
{
	slidercb.SetPosition(slidercb.getPosition()-1);
}

Crossfade.onToggle(boolean on)
{
	if (!on)
	{
		fadertext.setAlpha(150);
		CFIncrease.setAlpha(150);
		CFDecrease.setXmlParam("ghost" , "1");
		CFDecrease.setAlpha(150);
		CFIncrease.setXmlParam("ghost" , "1");
		CrossfadeActive.hide();
	}
	else
	{
		fadertext.setAlpha(255);
		CFIncrease.setAlpha(255);
		CFDecrease.setAlpha(255);
		CFIncrease.setXmlParam("ghost" , "0");
		CFDecrease.setXmlParam("ghost" , "0");
		CrossfadeActive.show();
	}
}

Global Boolean cfDown, onDown, autoDown;
Crossfade.onLeftButtonDown (int x, int y)
{
	cfDown = 1;
	CrossfadeActive.setXmlParam("y", integerToString(CrossfadeActive_Y+1));
}

Crossfade.onLeftButtonUp (int x, int y)
{
	cfDown = 0;
	CrossfadeActive.setXmlParam("y", integerToString(CrossfadeActive_Y));
}

Crossfade.onleaveArea ()
{
	CrossfadeActive.setXmlParam("y", integerToString(CrossfadeActive_Y));
}

Crossfade.onEnterArea ()
{
	if (cfDown) CrossfadeActive.setXmlParam("y", integerToString(CrossfadeActive_Y+1));
}


eqon.onEnterArea ()
{
	if (onDown) eqonActive.setXmlParam("y", integerToString(eqonActive_Y+1));
}

eqon.onLeftButtonDown (int x, int y)
{
	onDown = 1;
	eqonActive.setXmlParam("y", integerToString(eqonActive_Y+1));
}

eqon.onLeftButtonUp (int x, int y)
{
	onDown = 0;
	eqonActive.setXmlParam("y", integerToString(eqonActive_Y));
}

eqon.onleaveArea ()
{
	eqonActive.setXmlParam("y", integerToString(eqonActive_Y));
}


eqauto.onLeftButtonDown (int x, int y)
{
	autoDown = 1;
	eqautoActive.setXmlParam("y", integerToString(eqautoActive_Y+1));
}

eqauto.onLeftButtonUp (int x, int y)
{
	autoDown = 0;
	eqautoActive.setXmlParam("y", integerToString(eqautoActive_Y));
}

eqauto.onleaveArea ()
{
	eqautoActive.setXmlParam("y", integerToString(eqautoActive_Y));
}

eqauto.onEnterArea ()
{
	if (autoDown) eqautoActive.setXmlParam("y", integerToString(eqautoActive_Y+1));
}


btnEQp12.onLeftClick()
{
	for(int i=0; i<10; i++) setEqBand(i, 127);
}

btnEQ0.onLeftClick()
{
	for(int i=0; i<10; i++) setEqBand(i, 0);
}

btnEQm12.onLeftClick()
{
	for(int i=0; i<10; i++) setEqBand(i, -127);
}